#include "functions.h"
#include <vector>
#include "../../externals/PixelToaster.h"

// =================================================================================================
// Checks for interception and returns the color
// =================================================================================================
void PlaneIntersection(const Vector4& or, const Vector4& dir, Plane& plane, float max, 
	                    float& sample, PixelToaster::Pixel& pixel) {
    // - compute d of the plane
	float d1 = -(DotProduct(plane.normal, or));
	float d = d1 + (DotProduct(plane.normal, plane.origin));
	float denom = (DotProduct(plane.normal, dir));
    float t = d/denom;

	// -- return some color of the surface
    if(sample > t && t > 0.0f) {
		sample = t;
		pixel.r = plane.color.r;
		pixel.g = plane.color.g;
		pixel.b = plane.color.b;
	}
}

// =================================================================================================
// Rotate about an arbitrary axis
// =================================================================================================
void RotateArb(const Vector4& vec, float radians, Matrix4x4& mat) {
}

// =================================================================================================
// Rotation functions
// =================================================================================================
void RotateX(float radians, Matrix4x4& mat) {
    Matrix4x4 temp;

    temp.m00 = 1.0f;
    temp.m11 = cos(radians);
    temp.m12 = sin(radians);
    temp.m21 = -sin(radians);
    temp.m22 = cos(radians);

    mat *= temp;
}

void RotateY(float radians, Matrix4x4& mat) {
    Matrix4x4 temp;

    temp.m00 = cos(radians);
    temp.m02 = sin(radians);
    temp.m11 = 1.0f;
    temp.m20 = -sin(radians);
    temp.m22 = cos(radians);

    mat *= temp;
}

void RotateZ(float radians, Matrix4x4& mat) {
    Matrix4x4 temp;

    temp.m00 = cos(radians);
    temp.m01 = -sin(radians);
    temp.m10 = sin(radians);
    temp.m11 = cos(radians);
    temp.m22 = 1.0f;

    mat *= temp;
}

// ==== End of Rotation Functions ==================================================================


